package simulation;

import java.text.DecimalFormat;

import streaming.StreamingConfig;

public class Logs {
	public static void printMessage (String sourceObject, String message){
		if (sourceObject == "main"){
			System.out.println(message);
			FileLog.getInstance().appendStringLog(message + "\n");
		}
		
		if (sourceObject == "summary") {
//			System.out.println(message);
			FileLog.getInstance().appendStringParameters(message + "\n");
		}

		if (sourceObject == "handleRequestMC") {
//			System.out.println(message);
//			FileLog.getInstance().appendStringLog(message + "\n");
		}
		
		if (sourceObject == "comparatorModule"){
//			System.out.println(message);
//			FileLog.getInstance().appendStringLog(message + "\n");
		}
		
		if (sourceObject == "notifyNeighbors"){
//			System.out.println(message);
//			FileLog.getInstance().appendStringLog(message + "\n");
		}
		
		if (sourceObject == "notifyPackets"){
//			System.out.println(message);
//			FileLog.getInstance().appendStringLog(message + "\n");
		}
		
		if (sourceObject == "handleNotify"){
//			System.out.println(message);
//			FileLog.getInstance().appendStringLog(message + "\n");
		}
		
		if (sourceObject == "requestPacket"){
//			System.out.println(message);
//			FileLog.getInstance().appendStringLog(message + "\n");
		}
		
		if (sourceObject == "sendPacket"){
//			System.out.println(message);
//			FileLog.getInstance().appendStringLog(message + "\n");
		}
		
		if (sourceObject == "handleRequest"){
//			System.out.println(message);
//			FileLog.getInstance().appendStringLog(message + "\n");
		}
		
		if (sourceObject == "handlePacket"){
//			System.out.println(message);
//			FileLog.getInstance().appendStringLog(message + "\n");
		}
		
		if (sourceObject == "handleOverride"){
//			System.out.println(message);
//			FileLog.getInstance().appendStringLog(message + "\n");
		}		

		if (sourceObject == "cmp_handlePacket"){
//			System.out.println(message);
//			FileLog.getInstance().appendStringLog(message + "\n");
		}
		
		if (sourceObject == "Tracker") {
//			System.out.println(message);
//			FileLog.getInstance().appendStringLog(message + "\n");
		}
		
		if (sourceObject == "Tracker_T_Set") {
//			System.out.println(message);
			FileLog.getInstance().appendStringParameters(message + "\n");
		}
		
		if (sourceObject == "mc_u_set_insertion") {
//			System.out.println(message);
//			FileLog.getInstance().appendStringLog(message + "\n");
		}
	}
	
	public static void printConfig(Double pacotesGerados, Double mediaPacotesGerados){
		DecimalFormat format = new DecimalFormat();  
	    format.setMaximumFractionDigits(4);  
	    format.setMinimumFractionDigits(2);  
		
		printMessage("summary", "-------------------- Dados da Simulação --------------------");
		printMessage("summary", "Janela de Disponibilidade: " + StreamingConfig.MCASTWINDOWSIZE);
		printMessage("summary", "Janela de Interesse: " + StreamingConfig.MCASTINTERESTWINDOWSIZE);
		printMessage("summary", "Max Outstanding: " + StreamingConfig.MCASTMAXOUTSTANDING);
		printMessage("summary", "Tempo execução: " + Config.TIME);
		printMessage("summary", "Pacotes gerados: " + pacotesGerados);
		printMessage("summary", "Média de pacotes trocados: " + mediaPacotesGerados);
		printMessage("summary", "Média de pacotes perdidos: " + (pacotesGerados-mediaPacotesGerados));
		printMessage("summary", "Média de pacotes perdidos: " + format.format((double)((pacotesGerados-mediaPacotesGerados)/pacotesGerados*100)) + "%");
		printMessage("summary", "Chunks por segundo: " + StreamingConfig.MCASTRATE);
		printMessage("summary", "------------------------------------------------------------");
	}
}
